/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.portalnahouby.serviceimplementation;

import cz.muni.fi.pa165.portalnahouby.daointerface.PickerDAO;
import cz.muni.fi.pa165.portalnahouby.dto.PickerDTO;
import cz.muni.fi.pa165.portalnahouby.entity.Picker;
import cz.muni.fi.pa165.portalnahouby.serviceinterface.PickerService;
import cz.muni.fi.pa165.portalnahouby.util.EntityDTOConvertor;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.ejb.SessionContext;

/**
 * Implementation of picker service
 *
 * @author Lukas Marica
 */
@Stateless
@Local(value = PickerService.class)
public class PickerServiceImpl implements PickerService {

    @Resource
    private SessionContext ctx;
    @EJB
    private PickerDAO pickerDAO;

    public void setPickerDAO(PickerDAO pickerDAO) {
        this.pickerDAO = pickerDAO;
    }

    @Override
    public void addPicker(PickerDTO picker) {
        Picker pickerEntity = EntityDTOConvertor.convertPicker(picker);
        pickerDAO.addPicker(pickerEntity);
        picker.setId(pickerEntity.getId());
    }

    @Override
    public void editPicker(PickerDTO picker) {
        pickerDAO.editPicker(EntityDTOConvertor.convertPicker(picker));
    }

    @Override
    public void deletePicker(Long id) {
        pickerDAO.deletePicker(id);
    }

    @Override
    public PickerDTO findPicker(Long id) {
        return EntityDTOConvertor.convertPicker(pickerDAO.findPicker(id));
    }

    @Override
    public List<PickerDTO> getAllPickers() {
        List<Picker> entityList = pickerDAO.getAllPickers();
        List<PickerDTO> dtoList = new ArrayList<PickerDTO>();
        for (Picker picker : entityList) {
            dtoList.add(EntityDTOConvertor.convertPicker(picker));
        }

        return dtoList;
    }
}
